//
//  InfoViewController.m
//  YiqiMobile
//
//  Created by henry on 13-3-29.
//  Copyright (c) 2013年 henry. All rights reserved.
//

#import "InfoViewController.h"
#import "FirstViewController.h"
#import "SecondViewController.h"
#import "ThirdViewController.h"
#import "FourthViewController.h"
#import "Utility.h"
#import "Config.h"



@interface InfoViewController ()


@end


@implementation InfoViewController


- (void)viewDidLoad{
    [super viewDidLoad];
    self.isfirstload=YES;
    float height=367;
    if (iPhone5) {
        height+=88;
    }
    self.contentView=[[UIView alloc] initWithFrame:CGRectMake(0, 44, 320, height)];
    [self.view addSubview:self.contentView];
    
    FirstViewController *firstViewController=[[FirstViewController alloc] initWithNibName:@"FirstViewController" bundle:nil];
    [self addChildViewController:firstViewController];
    SecondViewController *secondViewController=[[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil];
    [self addChildViewController:secondViewController];
    ThirdViewController *thirdViewController=[[ThirdViewController alloc] initWithNibName:@"SecondViewController" bundle:nil];
    [self addChildViewController:thirdViewController];
    
    FourthViewController *fourthViewController=[[FourthViewController alloc] initWithNibName:@"SecondViewController" bundle:nil];
    [self addChildViewController:fourthViewController];
    
    [self.contentView addSubview:firstViewController.view];
    
    self.currentViewController=firstViewController;
    
}

-(void) viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    if (self.isfirstload) {
         [self showSubMenu];
         self.isfirstload=!self.isfirstload;
    }
}

-(void) showSubMenu{
    UIView *bgview=[[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];
    bgview.backgroundColor=[UIColor colorWithRed:32.0/255 green:32.0/255 blue:32.0/255 alpha:1.0];
    [self.view addSubview:bgview];
    
    UIButton *button1=[Utility customButton:self action:@selector(onClickbutton:) normalImage:@"info_pinglun_normal.png" lightedImage:@"info_pinglun_hover.png" frame:CGRectMake(20, 7, 60, 30) title:nil tag:INFOBUTTONTAG+1];
   [bgview addSubview:button1];
   [bgview addSubview:[Utility customButton:self action:@selector(onClickbutton:) normalImage:@"info_sms_normal.png" lightedImage:@"info_sms_hover.png" frame:CGRectMake(95, 7, 60, 30) title:nil tag:INFOBUTTONTAG+2]];
   [bgview addSubview:[Utility customButton:self action:@selector(onClickbutton:) normalImage:@"info_noti_normal.png" lightedImage:@"info_noti_hover.png" frame:CGRectMake(168, 7, 60, 30) title:nil tag:INFOBUTTONTAG+3]];
   [bgview addSubview:[Utility customButton:self action:@selector(onClickbutton:) normalImage:@"info_apply_normal.png" lightedImage:@"info_apply_hover.png" frame:CGRectMake(242, 7, 60, 30) title:nil tag:INFOBUTTONTAG+4]];
    
    [self onClickbutton:button1];
}


-(IBAction)onClickbutton:(id)sender{
    UIButton *selectButton=(UIButton*)sender;
    for (int i=1; i<5; i++) {
        UIButton *button=(UIButton*)[self.view viewWithTag:INFOBUTTONTAG+i];
        button.selected=NO;
    }
    selectButton.selected=YES;
    int tag=[sender tag]-INFOBUTTONTAG;
    FirstViewController *firstViewController=[self.childViewControllers objectAtIndex:0];
    SecondViewController *secondViewController=[self.childViewControllers objectAtIndex:1];
    ThirdViewController *thirdViewController=[self.childViewControllers objectAtIndex:2];
     FourthViewController *fourthViewController=[self.childViewControllers objectAtIndex:3];
    if ((self.currentViewController==firstViewController&&tag==1)||(self.currentViewController==secondViewController&&tag==2) ||(self.currentViewController==thirdViewController&&tag==3)||(self.currentViewController==fourthViewController&&tag==4) ) {
        return;
    }
    UIViewController *oldViewController=self.currentViewController;
    switch (tag) {
        case 1:{
            [self transitionFromViewController:self.currentViewController toViewController:firstViewController duration:0.5 options:UIViewAnimationOptionTransitionFlipFromLeft animations:^{
            }  completion:^(BOOL finished) {
                if (finished) {
                    self.currentViewController=firstViewController;
                }else{
                    self.currentViewController=oldViewController;
                }
            }];
             break;
        }
           
        case 2:{
            [self transitionFromViewController:self.currentViewController toViewController:secondViewController duration:0.5 options:UIViewAnimationOptionTransitionFlipFromTop animations:^{
                
            }  completion:^(BOOL finished) {
                if (finished) {
                    self.currentViewController=secondViewController;
                }else{
                    self.currentViewController=oldViewController;
                }
            }];
            break;
        }
            
        case 3: {
            [self transitionFromViewController:self.currentViewController toViewController:thirdViewController duration:0.5 options:UIViewAnimationOptionTransitionFlipFromBottom animations:^{
                
            }  completion:^(BOOL finished) {
                if (finished) {
                    self.currentViewController=thirdViewController;
                }else{
                    self.currentViewController=oldViewController;
                }
            }];
             break;
        }
        case 4: {
            [self transitionFromViewController:self.currentViewController toViewController:fourthViewController duration:0.5 options:UIViewAnimationOptionTransitionCurlDown animations:^{
                
            }  completion:^(BOOL finished) {
                if (finished) {
                    self.currentViewController=fourthViewController;
                }else{
                    self.currentViewController=oldViewController;
                }
            }];
            break;
        }
  
       
    }
}

- (void)didReceiveMemoryWarning

{
    
    [super didReceiveMemoryWarning];
    
    // Dispose of any resources that can be recreated.
    
}
@end